<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.tags.PageModel" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.admin.utils.SiteHelper" %>
<%@ page import="com.qipay.baas.model.Sp" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.baas.model.SpRonghuiMch" %>
<%@ page import="com.qipay.admin.spronghuimch.vo.SpRonghuiBanlanceVo" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">商户列表</h3>
                            <a class="btn btn-success"
                               href="${pageContext.request.contextPath}/sp/ronghuimch/add">商户进件</a>
                        </div>
                        <div class="col-xs-10">
                            <form class="form-inline">
                                <span class="help-inline"> 渠道名称：</span> <input type="text" id="textmerchantName"
                                                                             value="<%= request.getParameter("merchantName")!=null?request.getParameter("merchantName"):""%>"/>
                                <span class="help-inline"> 状态：</span>
                                <select id="ddltype">
                                    <option value="-1">全部</option>
                                    <option value="0">已入网</option>
                                    <option value="1">未入网</option>
                                </select>
                                    <button type="button" class="button back-gray" id="btnSearch">查询</button>
                                </form>
                        </div>
                        <hr>
                        <!-- /.box-header -->
                        <div class="box-body">
                               <% SpRonghuiBanlanceVo balance = (SpRonghuiBanlanceVo) request.getAttribute("balance");%>
                            <tr>
                                <td colspan="18">银联总余额：<%=balance.getBalance() %>&nbsp&nbsp </td>
                                <td colspan="18">可用余额：<%=balance.getCanbalance()%>&nbsp&nbsp </td>
                            </tr>
                                <%--</table>--%>

                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                  <%--  <th>渠道名称</th>
                                    <th>渠道编码</th>--%>
                                    <th>商户名称</th>
                                    <th>商户编号</th>
                                    <th>商户类型</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <% List<SpRonghuiMch> articles = (List<SpRonghuiMch>) request.getAttribute("lst");
                                    PageModel pager = (PageModel) request.getAttribute("page");
//                                    SpRonghuiBanlanceVo balance = (SpRonghuiBanlanceVo) request.getAttribute("balance");
                                    String query = pageContext.getRequest().getServletContext().getContextPath() + "/sp/ronghuimch/" + pager.getUrl();
                                    query = StringUtils.replace(query, "s=null", "s=");
                                    if (articles != null && articles.size() > 0) {
                                        Iterator<SpRonghuiMch> iter = articles.iterator();
                                        SpRonghuiMch user = null;
                                        while (iter.hasNext()) {
                                            user = iter.next();
                                %>
                                <tr id="user_<%=user.getId()%>">
                                    <td><%=user.getId()%></td>
                              <%--      <td><%=user.getChannelName()%>
                                    </td>
                                    <td><%=user.getChannelNo()%></td>--%>
                                    <td><%=user.getMerchantName()%></td>
                                    <td><%=user.getMerchantNo()%></td>
                                    <td><%=user.getMerchantType()%></td>
                                    <td><%=SiteHelper.getNetState(user.getState()) %></td>

                                    <td>
                                        <%if(!StringUtils.isEmpty(user.getMerchantNo())){%>
                                          <a class="button back-gray btn-xs"
                                             href="${pageContext.request.contextPath}/sp/ronghuimch/<%= user.getId()%>/paytype">支付类型</a>
                                        <%}%>
                                        <%--用户状态为未申请入网才可以申请入网/修改--%>
                                        <% if (user.getState() != null&&user.getState()!=(byte)0) {%>
                                        <a class="button back-gray btn-xs" name="deleteFlag" href="javascript:;"
                                           pk="<%= user.getId()%>">删除</a>
                                        <a name="linkNet"
                                           pk="<%= user.getId()%>" class="btn btn-danger btn-xs">申请入网</a>


                                        <%}%>
                                        <a name="linkSearch"
                                           pk="<%= user.getId()%>" class="btn btn-danger btn-xs">入件查询</a>
                                        <a class="button back-gray btn-xs"
                                           href="${pageContext.request.contextPath}/sp/ronghuimch/<%= user.getId()%>">修改</a>
                                    </td>
                                </tr>
                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="5">no data.</td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>

                            <div class="col-sm-10">

                                <div class="dataTables_paginate paging_simple_numbers" id="example1_paginate">
                                    <page:page totalSum="<%= pager.getTotal()%>"
                                               url="<%= query%>"
                                               pageNo="<%= pager.getPage()%>"
                                               pageSize="<%= pager.getPageSize()%>"></page:page>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>
    $(function () {
        var state = parseInt("<%= StringUtils.isNotEmpty(request.getParameter("state"))?request.getParameter("state"):-1%>", 10);
        $("#ddltype").val(state);
        $("#btnSearch").on("click", function () {
            var merchantName = $.trim($("#textmerchantName").val());
            var state = $("#ddltype").val();
            if (state == null || state == "null") {
                state = -1;
            }
            window.location.href = "${pageContext.request.contextPath}/sp/ronghuimch?merchantName=" + encodeURIComponent(merchantName)+"&state=" + (state == -1 ? "" : state) ;
        });

        //确定标记删除
        $("[name='deleteFlag']").click(function () {
            var pk = $(this).attr("pk");
            if (pk > 0) {
                if (confirm("确定删除吗？")) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/ajax?n=deleteById&id=" + pk,
                        type: "GET",
                        async: true,//true异步 false同步
                        context: this,
                        timeout: 10000,
                        success: function (data) {
                            if (data != null && data == "1") {
                                $("#user_" + pk).hide(100);
                            }
                            else {
                                alert("fail:" + data);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }

        });
        //申请入网
        $("[name='linkNet']").click(function () {
            var pk = $(this).attr("pk");
            if (pk > 0) {
                if (confirm("确认申请入网？")) {
                    $.ajax({
                        url: "/sp/ronghuimch/" + pk + "/apply",
                        type: "POST",
                        async: true,//true异步 false同步
                        context: this,
                        dataType: "json",
                        success: function (data) {
                            console.log(data);
                            if (data != null && data.code == "1") {
                                alert("进件成功:");
                                location.reload(true)

                            }
                            else {
                                alert("fail:" + data.msg);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }

        });
        //入件查询
        $("[name='linkSearch']").click(function () {
            var pk = $(this).attr("pk");
            if (pk > 0) {
                if (confirm("确认查询入网？")) {
                    $.ajax({
                        url: "/sp/ronghuimch/" + pk + "/search",
                        type: "POST",
                        async: true,//true异步 false同步
                        context: this,
                        dataType: "json",
                        success: function (data) {
                            console.log(data);
                            if (data != null && data.code == "1") {
                                alert("查询成功");
                                location.reload(true)
                            }
                            else {
                                alert("fail:" + data.msg);
                            }
                        },
                        error: function (d, s, b) {
                            alert("失败:" + b);
                        }
                    });
                }
            }

        });


    });
</script>
</body>
</html>

